/*     */ package com.zimbra.qa.unittest.prov.ldap;
/*     */ 
/*     */ import com.zimbra.common.account.Key.AccountBy;
/*     */ import com.zimbra.common.account.Key.DataSourceBy;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.AccountServiceException;
/*     */ import com.zimbra.cs.account.DataSource;
/*     */ import com.zimbra.cs.account.Domain;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.qa.unittest.prov.Names;
/*     */ import com.zimbra.soap.admin.type.CacheEntryType;
/*     */ import java.util.HashMap;
/*     */ import java.util.HashSet;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.Set;
/*     */ import org.junit.AfterClass;
/*     */ import org.junit.Assert;
/*     */ import org.junit.BeforeClass;
/*     */ import org.junit.Test;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class TestLdapProvDataSource
/*     */   extends LdapTest
/*     */ {
/*     */   private static LdapProvTestUtil provUtil;
/*     */   private static Provisioning prov;
/*     */   private static Domain domain;
/*     */   
/*     */   @BeforeClass
/*     */   public static void init()
/*     */     throws Exception
/*     */   {
/*  45 */     provUtil = new LdapProvTestUtil();
/*  46 */     prov = provUtil.getProv();
/*  47 */     domain = provUtil.createDomain(baseDomainName(), null);
/*     */   }
/*     */   
/*     */   @AfterClass
/*     */   public static void cleanup() throws Exception {
/*  52 */     Cleanup.deleteAll(new String[] { baseDomainName() });
/*     */   }
/*     */   
/*     */   private Account createAccount(String localPart) throws Exception {
/*  56 */     return createAccount(localPart, null);
/*     */   }
/*     */   
/*     */   private Account createAccount(String localPart, Map<String, Object> attrs) throws Exception
/*     */   {
/*  61 */     return provUtil.createAccount(localPart, domain, attrs);
/*     */   }
/*     */   
/*     */   private void deleteAccount(Account acct) throws Exception {
/*  65 */     provUtil.deleteAccount(acct);
/*     */   }
/*     */   
/*     */   private DataSource createDataSourceRaw(Account acct, String dataSourceName) throws Exception
/*     */   {
/*  70 */     return provUtil.createDataSourceRaw(acct, dataSourceName);
/*     */   }
/*     */   
/*     */   private DataSource createDataSource(Account acct, String dataSourceName) throws Exception
/*     */   {
/*  75 */     return provUtil.createDataSource(acct, dataSourceName);
/*     */   }
/*     */   
/*     */   private void deleteDataSource(Account acct, DataSource dataSource) throws Exception {
/*  79 */     provUtil.deleteDataSource(acct, dataSource);
/*     */   }
/*     */   
/*     */   private Account getFresh(Account acct) throws Exception {
/*  83 */     prov.flushCache(CacheEntryType.account, null);
/*  84 */     return prov.get(Key.AccountBy.id, acct.getId());
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void createDataSource() throws Exception {
/*  89 */     String ACCT_NAME_LOCALPART = Names.makeAccountNameLocalPart(genAcctNameLocalPart());
/*  90 */     String DATA_SOURCE_NAME = Names.makeDataSourceName(genDataSourceName());
/*     */     
/*  92 */     Account acct = createAccount(ACCT_NAME_LOCALPART);
/*  93 */     DataSource dataSource = createDataSource(acct, DATA_SOURCE_NAME);
/*     */     
/*  95 */     Assert.assertEquals(acct.getId(), dataSource.getAccount().getId());
/*     */     
/*  97 */     deleteDataSource(acct, dataSource);
/*  98 */     deleteAccount(acct);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void createDataSourceAlreadyExists() throws Exception {
/* 103 */     String ACCT_NAME_LOCALPART = Names.makeAccountNameLocalPart(genAcctNameLocalPart());
/* 104 */     String DATA_SOURCE_NAME = Names.makeDataSourceName(genDataSourceName());
/*     */     
/* 106 */     Account acct = createAccount(ACCT_NAME_LOCALPART);
/* 107 */     DataSource dataSource = createDataSource(acct, DATA_SOURCE_NAME);
/*     */     
/* 109 */     boolean caughtException = false;
/*     */     try {
/* 111 */       createDataSourceRaw(acct, DATA_SOURCE_NAME);
/*     */     } catch (AccountServiceException e) {
/* 113 */       if ("account.DATA_SOURCE_EXISTS".equals(e.getCode())) {
/* 114 */         caughtException = true;
/*     */       }
/*     */     }
/* 117 */     Assert.assertTrue(caughtException);
/*     */     
/* 119 */     deleteDataSource(acct, dataSource);
/* 120 */     deleteAccount(acct);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void modifyDataSource() throws Exception {
/* 125 */     String ACCT_NAME_LOCALPART = Names.makeAccountNameLocalPart(genAcctNameLocalPart());
/* 126 */     String DATA_SOURCE_NAME = Names.makeDataSourceName(genDataSourceName());
/*     */     
/* 128 */     Account acct = createAccount(ACCT_NAME_LOCALPART);
/* 129 */     DataSource dataSource = createDataSource(acct, DATA_SOURCE_NAME);
/*     */     
/* 131 */     Map<String, Object> attrs = new HashMap();
/* 132 */     String MODIFIED_ATTR_NAME = "zimbraDataSourceHost";
/* 133 */     String MODIFIED_ATTR_VALUE = "modifyDataSource.com";
/* 134 */     attrs.put(MODIFIED_ATTR_NAME, MODIFIED_ATTR_VALUE);
/* 135 */     prov.modifyDataSource(acct, dataSource.getId(), attrs);
/*     */     
/* 137 */     acct = getFresh(acct);
/* 138 */     dataSource = prov.get(acct, Key.DataSourceBy.name, DATA_SOURCE_NAME);
/* 139 */     Assert.assertEquals(MODIFIED_ATTR_VALUE, dataSource.getAttr(MODIFIED_ATTR_NAME));
/*     */     
/* 141 */     deleteDataSource(acct, dataSource);
/* 142 */     deleteAccount(acct);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void renameDataSource() throws Exception {
/* 147 */     String ACCT_NAME_LOCALPART = Names.makeAccountNameLocalPart(genAcctNameLocalPart());
/* 148 */     String DATA_SOURCE_NAME = Names.makeDataSourceName(genDataSourceName());
/*     */     
/* 150 */     Account acct = createAccount(ACCT_NAME_LOCALPART);
/* 151 */     DataSource dataSource = createDataSource(acct, DATA_SOURCE_NAME);
/*     */     
/* 153 */     Map<String, Object> attrs = new HashMap();
/*     */     
/* 155 */     String MODIFIED_ATTR_NAME = "zimbraDataSourceName";
/* 156 */     String NEW_DATA_SOURCE_NAME = Names.makeDataSourceName(genDataSourceName("new"));
/* 157 */     String MODIFIED_ATTR_VALUE = NEW_DATA_SOURCE_NAME;
/* 158 */     attrs.put(MODIFIED_ATTR_NAME, MODIFIED_ATTR_VALUE);
/* 159 */     prov.modifyDataSource(acct, dataSource.getId(), attrs);
/*     */     
/* 161 */     acct = getFresh(acct);
/* 162 */     dataSource = prov.get(acct, Key.DataSourceBy.name, NEW_DATA_SOURCE_NAME);
/* 163 */     Assert.assertEquals(MODIFIED_ATTR_VALUE, dataSource.getAttr(MODIFIED_ATTR_NAME));
/*     */     
/* 165 */     deleteDataSource(acct, dataSource);
/* 166 */     deleteAccount(acct);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void getAllDataSources() throws Exception {
/* 171 */     String ACCT_NAME_LOCALPART = Names.makeAccountNameLocalPart(genAcctNameLocalPart());
/* 172 */     String DATA_SOURCE_NAME_1 = Names.makeDataSourceName(genDataSourceName("1"));
/* 173 */     String DATA_SOURCE_NAME_2 = Names.makeDataSourceName(genDataSourceName("2"));
/* 174 */     String DATA_SOURCE_NAME_3 = Names.makeDataSourceName(genDataSourceName("3"));
/*     */     
/* 176 */     Account acct = createAccount(ACCT_NAME_LOCALPART);
/* 177 */     DataSource dataSource1 = createDataSource(acct, DATA_SOURCE_NAME_1);
/* 178 */     DataSource dataSource2 = createDataSource(acct, DATA_SOURCE_NAME_2);
/* 179 */     DataSource dataSource3 = createDataSource(acct, DATA_SOURCE_NAME_3);
/*     */     
/* 181 */     acct = getFresh(acct);
/* 182 */     List<DataSource> allDataSources = prov.getAllDataSources(acct);
/* 183 */     Assert.assertEquals(3L, allDataSources.size());
/*     */     
/* 185 */     Set<String> allDataSourceIds = new HashSet();
/* 186 */     for (DataSource dataSource : allDataSources) {
/* 187 */       allDataSourceIds.add(dataSource.getId());
/*     */     }
/*     */     
/* 190 */     Assert.assertTrue(allDataSourceIds.contains(dataSource1.getId()));
/* 191 */     Assert.assertTrue(allDataSourceIds.contains(dataSource2.getId()));
/* 192 */     Assert.assertTrue(allDataSourceIds.contains(dataSource3.getId()));
/*     */     
/* 194 */     deleteDataSource(acct, dataSource1);
/* 195 */     deleteDataSource(acct, dataSource2);
/* 196 */     deleteDataSource(acct, dataSource3);
/* 197 */     deleteAccount(acct);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void getDataSource() throws Exception {
/* 202 */     String ACCT_NAME_LOCALPART = Names.makeAccountNameLocalPart(genAcctNameLocalPart());
/* 203 */     String DATA_SOURCE_NAME = Names.makeDataSourceName(genDataSourceName());
/*     */     
/* 205 */     Account acct = createAccount(ACCT_NAME_LOCALPART);
/* 206 */     DataSource dataSource = createDataSource(acct, DATA_SOURCE_NAME);
/* 207 */     String dataSourceId = dataSource.getId();
/*     */     
/* 209 */     acct = getFresh(acct);
/* 210 */     dataSource = prov.get(acct, Key.DataSourceBy.id, dataSourceId);
/* 211 */     Assert.assertNotNull(dataSource);
/*     */     
/* 213 */     acct = getFresh(acct);
/* 214 */     dataSource = prov.get(acct, Key.DataSourceBy.name, DATA_SOURCE_NAME);
/* 215 */     Assert.assertNotNull(dataSource);
/*     */     
/* 217 */     deleteDataSource(acct, dataSource);
/* 218 */     deleteAccount(acct);
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/prov/ldap/TestLdapProvDataSource.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */